<template>
  <div class="app-container">
    <div class="top">
      <div class="t_left">
        <p @click="zixunAdd()" style="background: #55ca7d">
          <svg-icon iconClass="jia" className="svg-icon"></svg-icon> 添加咨询
        </p>
        <p style="background: #ff5157">
          <svg-icon iconClass="shanchu" className="svg-icon"></svg-icon> 批量删除
        </p>
      </div>
      <div class="t_right">
        <span class="abb">资讯名称</span>
        <input v-model="value" type="text" placeholder="请输入" />
        <span class="chaxun" @click="chaxun()">
          <svg-icon iconClass="sousuo" className="svg-icon"></svg-icon>
          查询
        </span>
      </div>
    </div>
    <div class="table">
      <el-table
        :data="
          this.tableData.slice(
            (listQuery.pageIndex - 1) * listQuery.pageSize,
            (listQuery.pageIndex - 1) * listQuery.pageSize + listQuery.pageSize
          )
        "
        border
        style="width: 100%; textAlign: center"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="30"> </el-table-column>
        <el-table-column
          align="center"
          prop="title"
          label="标题"
          height="40px"
          width="180"
        >
        </el-table-column>
        <el-table-column align="center" prop="thumb" label="封面">
          <template slot-scope="scope">
            <img :src="scope.row.thumb" min-width="70" height="70" />
          </template>
        </el-table-column>
        <el-table-column align="center" prop="description" label="描述">
        </el-table-column>
        <el-table-column align="center" prop="'admin'" label="上传人">
          <template>
            <span>admin</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="create_time" label="添加时间">
        </el-table-column>
        <el-table-column align="center" prop="address" label="操作">
          <template slot-scope="scope">
            <template>
              <el-button type="text" @click="open2(scope.row)">
                <span
                  style="color: #38a28a; fontsize: 14px; cursor: pointer; margin: 10px"
                  >编辑</span
                >
              </el-button>
            </template>
            <template>
              <el-button type="text" @click="open(scope.row.id)">
                <span
                  style="color: #f44235; fontsize: 14px; cursor: pointer; margin: 10px"
                  >删除</span
                >
              </el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.pageIndex"
        :limit.sync="listQuery.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import pagination from "@/components/Pagination";
// import ZixunAlert from '@/components/ZixunAlert'
import { getTMS } from "@/api/news";
export default {
  name: "advisoryList",
  components: {
    pagination,
  },
  data() {
    return {
      listLoading: false,
      total: 0,
      listQuery: {
        pageIndex: 1,
        pageSize: 10,
      },
      typeList: {},
      tableData: [],
      value: "", //筛选value
      multipleSelection: [], //批量删除数据
      checked: true,
    };
  },
  computed: {},
  created() {
    this.getList();
    this.dialogFormVisible = false;
    let a = this.$store.state.user.zixun.data;
    this.tableData = a;
  },
  methods: {
    //模糊搜索
    chaxun() {
      console.log(this.tableData);
      console.log(this.value);
      let a = [];
      this.tableData.forEach((item, index) => {
        if (
          (item.title || item.description || item.category_name).indexOf(this.value) !==-1
        ) {
          // console.log(item);
          a.push(item);
        }
      });
      console.log(a);
    },
    //跳转添加咨询
    zixunAdd() {
      this.$router.push("/advisory/create");
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.dialogFormVisible = false;
    },
    getList(val) {
      if (val) {
        this.listQuery.pageIndex = val.page;
        this.listQuery.pageSize = val.limit;
      }
      console.log(this.tableData.length);
      this.listLoading = true;
      this.total = this.$store.state.user.zixun.data.length;
    },
    dialogVisible() {
      // console.log(11);
      this.dialogFormVisible = false;
    },
    open(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch('user/getZixunRemoteData',{})
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    open2(scope) {
      let {id} = scope
      this.$confirm("此操作将修改该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$router.push({
            path: "/advisory/create",
            query: {
              id: id,
            },
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消编辑",
          });
        });
    },
  },
  mounted() {
    this.$store.dispatch('user/getZixunData',{pageNo:'10',pageSize:'10',value:''})
  },
};
</script>

<style scoped>
.abb {
  margin-right: 15px;
  font-size: 14px;
}
.table {
  margin-top: 30px;
  padding-bottom: 20px;
}
.top {
  border: 1px solid #e5e5e5;
  box-sizing: border-box;
  padding: 15px;
}
.svg-icon {
  margin-right: 10px;
  color: #fff !important;
}
.chaxun {
  display: inline-block;
  padding: 6px 20px;
  font-size: 14px;
  margin-right: 15px;
  color: #fff;
  border-radius: 5px;
  background: #55ca7d;
  margin-left: 20px;
  cursor: pointer;
}
.t_right input {
  width: 200px;
  height: 30px;
  border-radius: 5px;
  border: 1px solid rgba(187, 187, 187, 100);
  padding-left: 15px;
}
.app-container {
  min-width: 1050px;
}
.top {
  overflow: hidden;
}
.t_left {
  float: left;
}
.t_left p {
  display: inline-block;
  padding: 6px 20px;
  font-size: 14px;
  margin-right: 15px;
  color: #fff;
  border-radius: 5px;
  cursor: pointer;
}
.t_right {
  float: right;
}
* {
  color: #101010;
}
</style>
